//
//  BannerCell.m
//  bannerViewTest
//
//  Created by 谢特 on 2017/5/16.
//  Copyright © 2017年 xiete. All rights reserved.
//

#import "XTBannerCell.h"

#if __has_include(<UIImageView+WebCache.h>)
#import <UIImageView+WebCache.h>
#else
#import "UIImageView+WebCache.h"
#endif

@interface XTBannerCell()
@property (nonatomic, strong)UIImageView *imageView;
@end
@implementation XTBannerCell
- (instancetype)init {
    if (self = [super init]) {
        [self.contentView addSubview:self.imageView];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self.contentView addSubview:self.imageView];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        [self.contentView addSubview:self.imageView];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.imageView.frame = self.bounds;
}

//- (void)setImageName:(NSString *)imageName{
//    imageName = imageName;
//    if (_imageName.length <=0) return;
//    if ([_imageName containsString:@"http://"]||[_imageName containsString:@"https://"]){
//        
//        [self.imageView sd_setImageWithURL:[NSURL URLWithString:_imageName] placeholderImage:[UIImage imageNamed:self.placeholder]];
//        
//    }else{
//        self.imageView.image = [UIImage imageNamed:_imageName];
//    }
//}

- (void)setImageData:(id)imageData{
    _imageData = imageData;
    if (!_imageData) return;
    if ([_imageData isKindOfClass:[UIImage class]]){
        self.imageView.image = imageData;
    }else if ([_imageData isKindOfClass:[NSString class]]){
        NSString *imageName = _imageData;
        if (imageName.length <=0) return;
        if ([imageName containsString:@"http://"]||[imageName containsString:@"https://"]){
            
            [self.imageView sd_setImageWithURL:[NSURL URLWithString:imageName] placeholderImage:[UIImage imageNamed:self.placeholder]];
            
        }else{
            self.imageView.image = [UIImage imageNamed:imageName];
        }
    }
}

- (UIImageView *)imageView{
    if (!_imageView){
        _imageView = [[UIImageView alloc] init];
        _imageView.backgroundColor = [UIColor whiteColor];
        _imageView.userInteractionEnabled = YES;
    }
    return _imageView;
}

@end
